package com.hcom.controller;

import com.hc.entity.User;
import com.hcom.utis.RandomUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;

/**
 * @Description：
 * @Author：曹杰克
 * @CreateTime：2022/10/28 17:24
 */
@RequestMapping("/mail")
@RestController
public class MailDemoController {

    @Autowired
    private JavaMailSender javaMailSender;

    @RequestMapping("/send")
    public String senderMail(@RequestBody User user) {
        SimpleMailMessage message = new SimpleMailMessage();
        // 发件人 你的邮箱
        message.setFrom("1439160371@qq.com");
        // 接收人 接收者邮箱
        message.setTo(user.getEmail());
        //邮件标题
        message.setSubject("hello");
        String code = RandomUtil.getSixBitRandom();
        //邮件内容
        message.setText("你好，我是陈冠希，我现在在洛杉矶，本次的验证码为:\t"+code+"\t"+"有效时间是5分钟，转我300块，等我回去给你300亿");
        javaMailSender.send(message);
        return "success";
    }
}

